package com.mttest.hotwords.comteoller;

import com.mttest.hotwords.common.ServerResponse;
import com.mttest.hotwords.dao.SearchLogMapper;
import com.mttest.hotwords.entity.SearchLog;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author sunqy
 * @description
 * @create 2020-09-03 10:33
 */
@Controller
public class TestSearchLogController {

    @Resource
    private SearchLogMapper searchLogMapper;


    @GetMapping("/searchLog/{id}")
    @ResponseBody
    public ServerResponse getSearchLog(@PathVariable Long id){
        SearchLog searchLog = searchLogMapper.selectById(id);
        return ServerResponse.createBySuccess(searchLog);
    }

    @PostMapping("/searchLog/create")
    @ResponseBody
    public ServerResponse createSearchLog(SearchLog searchLog){
        searchLog.setTime(new Date());
        int insert = searchLogMapper.insert(searchLog);
        return insert==1?ServerResponse.createBySuccess("插入成功"):ServerResponse.createByErrorMessage("新增失败");
    }
}
